/**
 * 功能描述
 */
define(function (require, exports, module) {
    //引入视图基类
    var ELView = require("elview");

    //assets
    var template = require("./assets/tpl/roomtypesprice_main.tpl");
    require("./assets/css/roomtypesprice_main.css");

    var roomTypesPriceSubnavComp = require("./component/roomTypesPriceSubnavComp");
    var monthComp = require("./component/monthComp");
    var roomTypesPriceCalendarComp = require("./component/roomTypesPriceCalendarComp");
    var roomTypesPriceFormComp = require("./component/roomTypesPriceFormComp");
    var roomTypeDataSvc = require("./store/roomTypeDataSvc");
    
    var App = ELView.extend({
        attrs: {
            template: template
        },
        initComponent: function (params, widget) {
        	roomTypesPriceSubnavComp.initComponent(params, widget);
        	monthComp.initComponent(params,widget);
        	roomTypesPriceFormComp.initComponent(params, widget);
        },
        afterInitComponent: function (params, widget) {
        	var subnav = widget.get("subnav");
        	
        	subnav.load("servicepoint", {
                callback: function(data) {
                    subnav.setData("servicepoint", data);
                    //查询楼宇
                    var pkServicePoint = widget.get("subnav").getValue("servicepoint");
            		
                    roomTypeDataSvc.getOrgBuilding(pkServicePoint,function(buildingData){
                    	subnav.setData("buiding", buildingData);
                    	if(buildingData.length>0){
                    		//查询房间类型
                        	var pkOrgbuilding = widget.get("subnav").getValue("buiding");
                        	roomTypeDataSvc.getRoomtype(pkServicePoint,pkOrgbuilding,function(roomTypeData){
                            	subnav.setData("roomtypes", roomTypeData);
                            	roomTypesPriceCalendarComp.initComponent(params, widget);
                            });
                    	}else{
                    		roomTypesPriceCalendarComp.initComponent(params, widget);
                    	}
                    });
                }
            });
        }
    });

    module.exports = App;
});
